package com.example.demo.controller;

import com.example.comon.domain.R;
import com.example.demo.domain.Bo.StudentListBo;
import com.example.demo.domain.Bo.addStudentBo;
import com.example.demo.domain.Student;
import com.example.demo.domain.Vo.studentListVo;
import com.example.demo.service.IStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/student")
@Api(value = "student",tags = "学生信息管理")
public class StudentController {

        @Autowired
       private IStudentService studentService;

        @GetMapping("/getStudentList")
        @ApiOperation("获取学生列表")
        public R<List<studentListVo>> getStudentList(StudentListBo bo){
            Student  student = new Student();
            student.setAccount(bo.getAccount());
            student.setName(bo.getName());
            List<studentListVo> list =  studentService.selectStudent(student);
            return R.success(list);
        }



        @PostMapping("/addStudent")
        @ApiOperation("增加学生")

        public R<Student > addStudent(@RequestBody addStudentBo bo){
            Student  student = new Student();
            student.setAccount(bo.getAccount());
            student.setName(bo.getName());
            student.setAge(bo.getAge());
            student.setHometown(bo.getHometown());
//            student.setNumber(bo.getNumber());
            studentService.insertStudent(student);
            return R.success(student);
        }

        @PostMapping("/updateStudentByAccount")
        @ApiOperation("修改学生")
        public R updateStudentByAccount(@RequestBody Student student){
            studentService.updateStudentByAccount(student);
            return R.success();
        }

        @DeleteMapping("/delStudentByAccount")
        @ApiOperation("删除学生")
        public R delStudentByAccount(String account){
            studentService.delStudentByAccount(account);
            return R.success();
        }




}
